//
//  DefViewController.m
//  fp
//
//  Created by xingshuai on 2020/11/9.
//

#import "DefViewController.h"

#import "SearchResultViewController.h"  // 搜索接果
#import "GodLessViewController.h"       // 校师佳课
#import "CompEduViewController.h"       // 素质教育
#import "HomeOneTableViewCell.h"        // cell
#import "homeTwoTableViewCell.h"        // cell
#import "HomeCourseView.h"              // 基础课程弹框

@interface DefViewController () <HomeSearchTextDelegate,UITableViewDelegate,UITableViewDataSource,ClickOneCellBtnImageDelegate>

// 数据展示
@property (nonatomic, strong) UITableView *table;
// 基础课程
@property (nonatomic, strong) HomeCourseView *courseView;

@end

@implementation DefViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 设置首页导航样式
    self.currentnavType = XSCurrentNavViewTypeHome;
    
    self.delegate = self;
    
    [self creatClassSearViewUI];
                
}

// 初始化ui
-(void)creatClassSearViewUI {
    [self.view addSubview:self.table];
    [self.table mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).offset(15);
        make.top.equalTo(self.homeNavView.mas_bottom);
        make.right.equalTo(self.view.mas_right).offset(-15);
        make.bottom.equalTo(self.view).offset(-5);
    }];
    
    [self.view addSubview:self.courseView];
    [self.courseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

-(HomeCourseView *)courseView {
    if (!_courseView) {
        _courseView = [[HomeCourseView alloc]init];
        _courseView.hidden = YES;
        _courseView.totalList = @[@"语文",@"英语",@"数学",@"外语",@"化学",@"历史",@"体育",@"政治",@"鳄鱼",@"汉语",@"唐朝",@"宋朝",@"明朝"];
    }
    return _courseView;
}

// 初始化collection
- (UITableView *)table {
    if (!_table) {
        _table = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _table.delegate = self;
        _table.dataSource = self;
        _table.backgroundColor = [UIColor clearColor];
        _table.showsVerticalScrollIndicator = NO;
        _table.contentInset = UIEdgeInsetsMake(10, 0, 0, 0);
        _table.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _table;
}

#pragma mark --UITableViewDelegate,UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0.01;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 41;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return indexPath.section == 0 ? ScreenWidth/2.3/1.3 : (ScreenWidth-30)/5.4*1.5;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return nil;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return nil;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        HomeOneTableViewCell *cell = [HomeOneTableViewCell cellWithTableView:tableView];
        cell.delegate = self;
        return cell;
    } else {
        homeTwoTableViewCell *cell = [homeTwoTableViewCell cellWithTableView:tableView];
        return cell;
    }
}

#pragma mark -- HomeSearchTextDelegate
-(void)searchTextEndEdit:(NSString *)searchString {
    SearchResultViewController *vc = [[SearchResultViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}


#pragma mark -- ClickOneCellBtnImageDelegate
/// ClickOneCellBtnImageDelegate
/// @param buttonTag 100 : 基础课程
/// —————— ————————— 101 : 素质教育
/// —————— ————————— 102 : 校师佳课
/// —————— ————————— 103 : 我的课程
/// —————— ————————— 104 : 播放历史
-(void)clickButtonTypeTag:(NSInteger)buttonTag {
    // 如果搜索ui在编辑状态则退出
    if (self.searchField.isEditing) {
        [self.searchField resignFirstResponder];
    }
    switch (buttonTag) {
        case 100:
            [self tapOneBtn];
            break;
        case 101:
            [self tapTwoBtn];
            break;
        case 102:
            [self tapThreeBtn];
            break;
        case 103:
            NSLog(@"我的课程");
            break;
        case 104:
            NSLog(@"播放历史");
            break;
            
        default:
            break;
    }
}

// 素质教育
-(void)tapOneBtn {
    self.courseView.hidden = NO;
}

// 素质教育
-(void)tapTwoBtn {
    CompEduViewController *vc = [[CompEduViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 校师佳课
-(void)tapThreeBtn {
    GodLessViewController *vc = [[GodLessViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
